package w83a.w83aOperacionesPaso.w83aDocumentacion;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONObject;

import w83a.w83aBeans.W83aCentroTrabajoBean;
import w83a.w83aBeans.W83aCentroTrabajoEqualsBean;
import es.ejie.frmk.presentacion.operacion.paso.Q70ActionPasoOP;
import es.ejie.frmk.presentacion.sesiondatos.Q70ContextoEJIE;

// TODO: Auto-generated Javadoc
/**
 * The Class W83bTablaAgrupacionesOP.java.
 *
 * @author Deusto Sistemas
 */
public class W83aSeleccionarCentroTrabajoOPAction extends Q70ActionPasoOP{

	
	protected void processOP(Q70ContextoEJIE contexto, ActionErrors errores, ActionMapping mapping,
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
			String fila = request.getParameter("fila");
			W83aCentroTrabajoEqualsBean centroTemp = new W83aCentroTrabajoEqualsBean();
			centroTemp.setCodCentroTrabajo(fila);
			
			List listaCentros = (ArrayList)contexto.get("w83aListaCentroTrabajo");
			W83aCentroTrabajoBean centro =  (W83aCentroTrabajoBean)listaCentros.get(listaCentros.indexOf(centroTemp));
			
			JSONObject jsonObject = new JSONObject();
			
			jsonObject.put("nifCentro", centro.getCifnif());
			jsonObject.put("numCentro", centro.getNumCentro());
			jsonObject.put("razonSocial", centro.getRazonSocial());
			jsonObject.put("provinciaCentro", centro.getCodTerritorio());
			jsonObject.put("municipioCentro", centro.getCodMunicipio());
			jsonObject.put("idCentroTrabajo", centro.getCodCentroTrabajo());
			jsonObject.put("domicilioCentro", centro.getDomicilio());
			jsonObject.put("cpCentro", centro.getCodPostal());
			jsonObject.put("codigoCentro",centro.getCodCentroTrabajo());
			response.setContentType("text/javascript;charset=iso-8859-1");
			response.setHeader("Pragma", "cache");
			response.setHeader("Expires", "0");
			response.setHeader("Cache-Control", "private");
			response.setStatus(HttpServletResponse.SC_OK);
			PrintWriter out = response.getWriter();
			out.print(jsonObject.toString());
			out.flush();
		
	}

	protected ActionForward processForward(Q70ContextoEJIE contexto, ActionErrors errors, ActionMapping mapping, 
			ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		return mapping.findForward("ok");
	}

}
